home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5877 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  98 lines

  1. Path: ix.netcom.com!netnews
  2. From: wzjn@ix.netcom.com (KPN )
  3. Newsgroups: comp.lang.c
  4. Subject: Re: More Modulus questions
  5. Date: 21 Feb 1996 18:43:54 GMT
  6. Organization: Netcom
  7. Message-ID: <4gfp5a$r8e@cloner2.ix.netcom.com>
  8. References: <Pine.SOL.3.90.960219171637.21117B-100000@eddie> <4gfnka$ni7@spanky.pls.ov.com>
  9. NNTP-Posting-Host: ix-frm-ma1-04.ix.netcom.com
  10. X-NETCOM-Date: Wed Feb 21 10:43:54 AM PST 1996
  11.  
  12. Good Afternoon,
  13.  
  14. Recently I asked a question concerning the proper use of the Modulus
  15. code. Many replied back to me to help clear up m confusion, and many
  16. replied back to the group to help me. I thank all of you for your time
  17. and expertise.
  18.  
  19. As I looked over what had been sent to me, a great deal of the
  20. responses helped by pointing out that what I was doing was incorrect -
  21. however, no one really showed me what I should be doing to correct the
  22. problem! Well, actually, a few examples were to be had, but were so far
  23. over my knowledge of C thus far, as to be useless to me. Thank you
  24. anyway to those who sent in.
  25.  
  26. Here again is my problem: (From æHow to Program CÆ second edition
  27. Deitel/Dietel - Write a program that reads an integer and determines,
  28. and prints how many digits in the integer are 7Æs)
  29.  
  30. #include <stdio.h>
  31.  
  32. main()
  33. {
  34.   int number;
  35.   int first, second, third, fourth;
  36.   int integer1, integer2, integer3, integer4; 
  37.  
  38.   printf("Enter a four digit number: ");
  39.   scanf("%d", &number);
  40.  
  41. /*
  42.    Split the four digit number into four seperate integers
  43. */
  44.  
  45.   first = number / 1000;
  46.   integer1 = number % 1000;
  47.  
  48.   second = integer1 / 100;
  49.   integer2 = integer1 % 100;
  50.  
  51.   third = integer2 / 10;
  52.   integer3 = integer2 % 10;
  53.  
  54.   fourth = integer3 / 1;
  55.   integer4 = integer3 % 1;
  56.  
  57. /*
  58.    Use modulas to determine if any integers are a 7
  59. */
  60.       
  61.    if (first % 7)
  62.       printf("First integer was a 7\n");
  63.    else
  64.       printf("Not a 7\n");
  65.  
  66. if (second % 7)
  67.       printf("second integer was a 7\n");
  68.    else
  69.       printf("Not a 7\n");
  70.  
  71. if (third % 7)
  72.       printf("third integer was a 7\n");
  73.    else
  74.       printf("Not a 7\n");
  75.  
  76. if (fourth % 7)
  77.       printf("fourth integer was a 7\n");
  78.    else
  79.       printf("Not a 7\n");
  80.  
  81.  
  82. Yes, I know that you may have a different style/ would write it
  83. differently / wouldnÆt do it this way, but thatÆs OK - IÆll learn. All
  84. that IÆm concerned about right now, is that if I enter the number 7000,
  85. it tells me that the first digit is not a seven, and all the rest are a
  86. 7.
  87.  
  88. Could this be explained to me in verbiage instead of a big complicated
  89. example using all sorts of code that I do not know yet? I know, that in
  90. the book IÆm teaching myself from, more than a few examples have IF
  91. statement conditioned by a Modulus code ... how (in words!!!) does this
  92. code work?
  93.  
  94. Thank you for your patience and expertise,
  95.  
  96. kevin
  97.  
  98.